<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/18
 * Time: 17:50
 */

namespace app\ext\controller;

use app\ext\service\ArticleService;
use app\ext\service\CateService;
use think\Controller;

class Index extends Controller
{
    public function index()
    {
        $where = [];
        $cate_id = input('c_id')?:0;
        if($cate_id > 0) $where['c_id'] = $cate_id;

        $model = new ArticleService();
        $list = $model->articleList($where);

        $cateService = new CateService();
        $cateList = $cateService->cateList();

        $this->assign('title','XIEear\'s ComicBookStore');
        return view('index',['list'=>$list,'cate'=>$cateList]);
    }

    public function detail()
    {
        $id = input('id');
        $model = new ArticleService();
        $article = $model->detail($id);

        $this->assign('title',$article['title']);
        return view('detail',['article'=>$article]);
    }

    public function save()
    {
        $articleService = new ArticleService();
        $res = $articleService->articleSave();
        $res['status'] && $this->success($res['msg']);
        $this->error('添加失败');
    }

    public function add()
    {
        $this->assign('title','发布');
        return view('editor');
    }

    public function del()
    {
        $articleService = new ArticleService();
        $res = $articleService->del();
        $res && $this->success('删除成功');
        $this->error('删除失败');
    }

    public function edit()
    {

    }
}